<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>评估准则构建生成</title>
    <meta name="description" content="评估准则构建软件">
    <!-- Bootstrap CSS -->
    <link href="assets/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
    <!-- 字体CSS -->
    <link href="assets/font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css" />
    <!-- 自定义样式 -->
    <link href="assets/css/style.css" rel="stylesheet" type="text/css" />
    <link href="assets/css/bootstrap-select/bootstrap-select.css" rel="stylesheet" type="text/css" />

    <link rel="stylesheet" href="./assets/layui/css/layui.css">
    <link rel="stylesheet" href="./assets/css/norm/normModule.css">

</head>

<body class="adminbody">
<div id="normMain">
    <div class="content-page">
        <!-- Start content -->
        <div class="content">
            <div class="row">
                <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12 col-xl-12">
                    <div class="card mb-3">
                        <div class="card-body" style='height:500px;'>
                            <form class="layui-form " action="">
                                <div class="layui-form-item layui-row">
                                    <div class="layui-inline layui-col-xs4">
                                        <label class="layui-form-label" for="standardName">准则名称 <span>*</span></label>
                                        <div class="layui-input-inline">
                                            <input type="text" name="number" lay-verify="required" autocomplete="off" class="layui-input"
                                                   id="standardName">
                                        </div>
                                    </div>
                                    <div class="layui-inline layui-col-xs4">
                                        <label class="layui-form-label" for="context">评估内容<span>*</span></label>
                                        <div class="layui-input-inline">
                                            <input type="text" name="number" lay-verify="required" autocomplete="off" class="layui-input"
                                                   id="context">
                                        </div>
                                    </div>
                                    <div class="layui-inline layui-col-xs4">
                                        <label class="layui-form-label" for="method">评估方法<span>*</span></label>
                                        <div class="layui-input-inline">
                                            <input type="text" name="number" lay-verify="required" autocomplete="off" class="layui-input"
                                                   id="method">
                                        </div>
                                    </div>
                                </div>

                                <div class="layui-form-item layui-row">
                                    <div class="layui-inline layui-col-xs4">
                                        <label class="layui-form-label" for="target">评估对象<span>*</span></label>
                                        <div class="layui-input-inline">
                                            <input type="text" name="number" lay-verify="required" autocomplete="off" class="layui-input"
                                                   id="target">
                                        </div>
                                    </div>
                                    <div class="layui-inline layui-col-xs4">
                                        <label class="layui-form-label" for="creater">创建人 <span>*</span></label>
                                        <div class="layui-input-inline">
                                            <input type="text" name="number" lay-verify="required" autocomplete="off" class="layui-input"
                                                   id="creater">
                                        </div>
                                    </div>
                                    <div class="layui-inline layui-col-xs4" id="categoryBox">
                                        <label class="layui-form-label" for="category">准则类别<span>*</span></label>

                                    </div>
                                </div>

                                <div class="layui-form-item layui-row">


                                </div>
                            </form>
                        </div>
                    </div><!-- end card-->
                </div>
                <div class="form-group col-xs-12 col-sm-12 col-md-6 col-lg-6 col-xl-6" style='margin: 20px auto'>
                    <form class="layui-form" action="">
                        <div class="layui-form-item" id="temCheck">
                            <input type="checkbox" name="" title="生成模板" lay-skin="primary" lay-filter="isModel" >
                        </div>
                    </form>
                    <button class="btn btn-primary btn-size col-xs-12 col-sm-12 col-md-6 col-lg-6 col-xl-6"
                            onclick="addNorm()" style="display:none;margin-left:0px;" id="addNorm">
                        生成准则
                    </button>
                    <button class="btn btn-primary btn-size col-xs-12 col-sm-12 col-md-6 col-lg-6 col-xl-6"
                            type="submit" onclick="infoCommit()">
                        提交
                    </button>
                </div>

            </div>
        </div>
    </div>
</div>
<script src="assets/js/modernizr.min.js"></script>
<script src="assets/js/jquery.min.js"></script>
<script src="assets/js/moment.min.js"></script>
<script src="assets/js/popper.min.js"></script>
<script src="assets/js/bootstrap.min.js"></script>
<script src="assets/js/bootstrap-select/bootstrap-select.js"></script>


<script src="assets/js/detect.js"></script>
<script src="assets/js/fastclick.js"></script>
<script src="assets/js/jquery.blockUI.js"></script>
<script src="assets/js/jquery.nicescroll.js"></script>

<!-- App js -->
<script src="./assets/layui/layui.js" charset="utf-8"></script>
<script>
    var dateTime,modelCheck=false,paramArr=['standardName','context','method','creater','target','category'];
    //模板按钮点击类型
    var btnType='';
    var layer;
    layui.use('layer', function(){
        layer=layui.layer;
    });

    // layui.use('form', function() {
    //     var form = layui.form;
    //
    // })


    $(function () {
        $.ajax({
            //请求方式
            type : "POST",
            //请求的媒体类型
            contentType: "application/x-www-form-urlencoded",
            //请求地址
            url : "/bs/standardManage/getAllType",
            //数据
            // data : data,
            //请求成功
            success : function(res) {
                var data=res.data,content=`<option value=""></option>`;
                var str=``;
                if (res.status==0){
                    for (let i of data){
                        content+=`<option value="${i}">${i}</option>`;
                    }
                    str=`<div class="layui-input-inline">
                              <select name="city" lay-verify="required" id="category" lay-filter="selFilter">
                                ${content}
                              </select>
                            </div>`;
                    $('.layui-inline label[for="category"]').parent().append(str);
                    layui.use('form', function() {
                        var form = layui.form;
                            form.render();
                    })
                }
            },
            //请求失败，包含具体的错误信息
            error : function(e){
                console.error(e.status);
                console.error(e.responseText);
            }
        });
    })
    layui.use(['form'], function () {
        var form = layui.form;
        form.on('checkbox(isModel)', function(data){
            console.log(data.elem); //得到checkbox原始DOM对象
            console.log(data.elem.checked); //是否被选中，true或者false
            modelCheck=data.elem.checked;
        })
    });
    layui.use('laydate', function(){
        var laydate = layui.laydate;
        //日期范围
        //日期时间选择器
        laydate.render({
            elem: '#date'
            ,type: 'datetime'
            ,done: function(value, date){
                console.log(value); //得到日期生成的值，如：2017-08-18
                dateTime=value;
            }
        });
    })
    //获取勾选类型
    function postType(val) {
        if (val=="norm"){
            $('#temCheck input').attr("title","生成模板");
            $('#temCheck .layui-form-checkbox span').text("生成模板");
        }else if(val=="normEdit"){
            $('#temCheck').parent().css({display:"none"})
        }else if (val=="tem"){
            $('#temCheck input').attr("title","生成准则");
            $('#temCheck .layui-form-checkbox span').text("生成准则");
            createName();
        }else if (val=="temEdit"){
            createName();
            $('#temCheck').parent().css({display:"none"});
            $('#addNorm').css({display:"block"});
            $('.form-group button[type="submit"]').text("模板修改");
            $('.form-group button').css({width:200});

        }
    }
    //提交
    function infoCommit() {
        var paramObj={},inpVal='',dateObj,obj,isCommit=true;
        for (let i of paramArr){
            inpVal=document.getElementById(i).value;
            paramObj[i]=inpVal;
        }
        obj=Object.assign(paramObj,dateObj)

        //传值
        for (let k in paramObj){
            if (!paramObj[k]){
                isCommit=false;
            }
        }
        console.log(isCommit)
        if (isCommit){
            window.parent.getInfo(obj,modelCheck);
        }else {
            layer.msg('您有未填内容，请检查！');
        }
    }
//    分类创建名称
    function createName() {
        $('.layui-inline label[for="standardName"]').text("模板名称");
    }
    function addNorm() {
        btnType='add';
        infoCommit();
    }
//    修改赋值
    function fillVal(data) {
        console.log(data)
        if (data){
            for (let i of paramArr){
                if (i!='id'&&i!='createTime'&&i!='category'){
                   $(`#${i}`).val(data[i]);
                }else if (i=='category'){
                    layui.use('form', function() {
                        var form = layui.form;
                        var select = `dd[lay-value=${data[i]} ]`;// 设置value
                        $("#category").val(data[i]);
                        $('#category').siblings("div.layui-form-select").find('dl').find(select).click();// 查找点击
                        form.render('select','selFilter');
                    })
                }
            }
            for (let k in data ){
                if (k=='modelName'){
                    $(`#standardName`).val(data['modelName']);
                }
            }
        }
    }
</script>
</body>

</html>